package com.tanhua.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.tanhua.admin.mapper.UserInfoMapper;
import com.tanhua.admin.pojo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: JinboYang
 * @Description:
 * @Date: Created in 19:29 2021/1/4
 * @ModifiedBy:
 */
@Service
@Slf4j
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * @Description: 根据用户id查询用户信息并返回
     * @Param:[id]
     * @return:com.tanhua.server.pojo.UserInfo
     * @Author:JinboYang
     * @Date:2021/1/4
     */
    public UserInfo queryUserInfoByUserId(Long id) {
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInfo::getUserId, id);
        return userInfoMapper.selectOne(queryWrapper);
    }

    /**
     * @Description: 查询用户列表信息
     * @Param:[queryWrapper]
     * @return:java.util.List<com.tanhua.server.pojo.UserInfo>
     * @Author:JinboYang
     * @Date:2021/1/5
     */
    public List<UserInfo> queryUserInfoList(QueryWrapper queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);
    }

    /**
     * @Description: 更新用户
     * @Param:[userInfo]
     * @return:java.lang.Boolean
     * @Author:JinboYang
     * @Date:2021/1/14
     */
    public Boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userInfo.getUserId());
        return this.userInfoMapper.update(userInfo, queryWrapper) > 0;
    }

    //查询城市列表
    public List<Map<String, Object>> queryCityList(List<Long> userIds) {
        return this.userInfoMapper.queryCityList(userIds);
    }

    //查询行业列表
    public List<Map<String, Object>> queryIndustryList(List<Long> userIds) {
        return this.userInfoMapper.queryIndustryList(userIds);
    }

    //查询性别列表
    public List<Map<String, Object>> queryGenderList(List<Long> userIds) {
        return this.userInfoMapper.queryGenderList(userIds);
    }

    //查询年龄列表
    public List<Map<String, Object>> queryAgeList(List<Long> userIds) {
        return this.userInfoMapper.queryAgeList(userIds);
    }

}
